home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
programming
/
other
/
jikes
/
src
/
option.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
17KB
|
480 lines
// $Id: option.cpp,v 1.7 1999/03/10 19:59:21 shields Exp $
//
// This software is subject to the terms of the IBM Jikes Compiler
// License Agreement available at the following URL:
// http://www.ibm.com/research/jikes.
// Copyright (C) 1996, 1998, International Business Machines Corporation
// and others. All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
#include <ctype.h>
#include "config.h"
#include "option.h"
#include "javasym.h"
#include "error.h"
//
//
//
bool ArgumentExpander::ArgumentExpanded(Tuple<char *> &arguments, char *file_name)
{
struct stat status;
FILE *afile = fopen(file_name, "r");
if (afile && (::SystemStat(file_name, &status) == 0))
{
char *buffer = new char[status.st_size + 2];
int file_size = fread(buffer, 1, status.st_size, afile);
buffer[file_size] = '\n';
for (int k = 0; k < file_size; k++)
{
//
// isgraph(c) is true if c is any printing character except space.
//
while ((! isgraph(buffer[k])) && buffer[k] != '\n' && buffer[k] != '\r')
k++;
if (buffer[k] != '\n' && buffer[k] != '\r')
{
int n;
for (n = k + 1; buffer[n] != '\n' && buffer[n] != '\r'; n++)
;
buffer[n] = U_NULL;
char *str = new char[n - k + 1];
strcpy(str, &buffer[k]);
arguments.Next() = str;
k = n;
}
}
delete [] buffer;
fclose(afile);
return true;
}
return false;
}
ArgumentExpander::ArgumentExpander(int argc_, char *argv_[])
{
Tuple<char *> arguments(8192);
for (int i = 0; i < argc_; i++)
{
char *argument = argv_[i];
if (argument[0] != '@' || (! ArgumentExpanded(arguments, argument + 1)))
{
char *str = new char[strlen(argument) + 1];
strcpy(str, argument);
arguments.Next() = str;
}
}
argc = arguments.Length();
argv = new char*[argc];
for (int k = 0; k < argc; k++)
argv[k] = arguments[k];
return;
}
ArgumentExpander::ArgumentExpander(Tuple<char> &line)
{
Tuple<char *> arguments(8192);
int end = 0;
do
{
for (; end < line.Length() && line[end] == U_SPACE; end++)
;
if (end < line.Length())
{
int start = end;
for (end++; end < line.Length() && line[end] != U_SPACE; end++)
;
int length = end - start;
char *argument = new char[length + 1];
for (int i = 0, k = start; k < end; i++, k++)
argument[i] = line[k];
argument[length] = U_NULL;
if (argument[0] == '@' && ArgumentExpanded(arguments, argument + 1))
delete argument;
else arguments.Next() = argument;
}
} while(end < line.Length());
argc = arguments.Length();
argv = new char*[argc];
for (int k = 0; k < argc; k++)
argv[k] = arguments[k];
return;
}
#ifdef WIN32_FILE_SYSTEM
void Option::SaveCurrentDirectoryOnDisk(char c)
{
if (! current_directory[c])
{
char *disk_directory = NULL,
disk[3] = { c, U_COLON, U_NULL },
tmp[1];
if (SetCurrentDirectory(disk))
{
DWORD directory_length = GetCurrentDirectory(0, tmp); // first, get the right size
disk_directory = new char[directory_length + 1]; // allocate the directory
DWORD length = GetCurrentDirectory(directory_length, disk_directory);
if (length <= directory_length)
{
for (char *ptr = disk_directory; *ptr; ptr++)
*ptr = (*ptr != U_BACKSLASH ? *ptr : (char) U_SLASH); // turn '\' to '/'.
}
}
if (! disk_directory)
{
disk_directory = new char[2];
strcpy(disk_directory, StringConstant::U8S__DO_);
}
current_directory[Case::ToAsciiLower(c)] = disk_directory;
current_directory[Case::ToAsciiUpper(c)] = disk_directory;
}
return;
}
#endif
Option::Option(ArgumentExpander &arguments) : default_path(NULL),
classpath(NULL),
makefile_name(NULL),
debug_dump_lex(false),
debug_dump_ast(false),
debug_dump_class(false),
debug_trap_op(false),
applet_author(false),
incremental(false),
makefile(false),
bytecode(true),
full_check(false),
unzip(false),
dump_errors(false),
errors(true),
ascii(false),
comments(false),
pedantic(false),
directory(NULL),
first_file_index(arguments.argc),
one_one(true),
g(false),
nowrite(false),
deprecation(false),
verbose(false),
depend(false),
nowarn(false),
O(false),
zero_defect(false)
{
#ifdef WIN32_FILE_SYSTEM
for (int j = 0; j < 128; j++)
current_directory[j] = NULL;
char tmp[1];
DWORD directory_length = GetCurrentDirectory(0, tmp); // first, get the right size
char *main_current_directory = new char[directory_length + 1]; // allocate the directory
DWORD length = GetCurrentDirectory(directory_length, main_current_directory);
if (length > directory_length)
{
delete [] main_current_directory;
main_current_directory = StringConstant::U8S__DO_;
main_disk = 0;
}
else
{
for (char *ptr = main_current_directory; *ptr; ptr++)
*ptr = (*ptr != U_BACKSLASH ? *ptr : (char) U_SLASH); // turn '\' to '/'.
main_disk = main_current_directory[0]; // the first character
current_directory[Case::ToAsciiLower(main_disk)] = main_current_directory;
current_directory[Case::ToAsciiUpper(main_disk)] = main_current_directory;
}
current_directory[0] = main_current_directory;
#endif
Tuple<int> filename_index(2048);
for (int i = 1; i < arguments.argc; i++)
{
if (arguments.argv[i][0] == '-')
{
if (strcmp(arguments.argv[i],"-classpath") == 0 && ((i + 1) < arguments.argc))
{
classpath = arguments.argv[++i];
#ifdef EBCDIC
//
// Maintain CLASSPATH in ASCII and translate back to EBCDIC when building file name
//
for (int k = 0; k < strlen(classpath); k++)
classpath[k] = Code::ToASCII(classpath[k]);
#endif
}
else if (strcmp(arguments.argv[i], "-depend") == 0)
depend = true;
else if (strcmp(arguments.argv[i],"-verbose") == 0)
verbose = true;
else if (strcmp(arguments.argv[i],"-g") == 0)
g = true;
else if (strcmp(arguments.argv[i], "-O") == 0)
O = true;
else if (strcmp(arguments.argv[i],"-deprecation") == 0)
{
bad_optio